package com.refusea.train.mapper

import com.refusea.train.domain.entity.Lesson
import org.apache.ibatis.annotations.Delete
import org.apache.ibatis.annotations.Insert
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Options
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.Update

@Mapper
interface LessonMapper {

    @Insert("INSERT INTO lesson (course_id, lesson_number, title, description) VALUES (#{courseId}, #{lessonNumber}, #{title}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    fun insert(lesson: Lesson): Int

    @Delete("DELETE FROM lesson WHERE id = #{id}")
    fun delete(id: Int): Int

    @Update("UPDATE lesson SET course_id = #{courseId}, lesson_number = #{lessonNumber}, title = #{title}, description = #{description} WHERE id = #{id}")
    fun update(lesson: Lesson): Int

    @Select("SELECT * FROM lesson WHERE id = #{id}")
    fun select(id: Int): Lesson?

    @Select("SELECT * FROM lesson")
    fun list(): List<Lesson>
}
